﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Baimasoft.FrameWork.Base;
using HsTec.Mobile.Green.SqlServerDAL;
using Baimasoft.Web.UI;

public partial class News_NewsBigClassForm :Baimasoft .Web .UI .PageFormTop
{
    NewsBigClass MyNBC = new NewsBigClass();

    #region 重写方法

    /// <summary>
    /// 初始化表单信息
    /// </summary>
    protected override void InitForm()
    {
        if (!Page.IsPostBack)
        {
            try
            {
                string sEditStatus = this.Request.QueryString["EditStatus"].ToString().Trim();
                if (sEditStatus == "2")
                {
                    string sID = this.Request.QueryString["ID"].ToString().Trim();
                    DataTable MyDT = MyNBC.GetNewsBigClassInfos(" ID = '" + sID + "' ");
                    foreach (DataRow dr in MyDT.Rows)
                    {
                        this.txtBigClassName.Text = dr["BigClassName"].ToString().Trim();
                        this.txtOrderby.Text      = dr["Orderby"].ToString().Trim();
                    }
                }

            }
            catch
            {
            }
        }
    }
    /// <summary>
    /// 保存数据
    /// </summary>
    protected override void SavaData()
    {
        try
        {
            string sid = "";

            if (this.Request.Params["ID"] != null)
            {
                sid = this.Request.Params["ID"].Trim();
            }
            else
            {
                sid = "-1";
            }

            string sBigClassName = this.txtBigClassName.Text;//大类名称
            int sOrderby = int.Parse(this.txtOrderby.Text);//排序
            string sPic = "";
            string sDemo = "";
            DateTime DAddtime = DateTime.Now.AddDays(0);


           //判断该大类名称是否已经存在

            string sName = this.txtBigClassName.Text;

            int count = MyNBC .GetCountName(sid, sName);
            if (count > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('该名称已经存在，请重新输入!');</script>");
                return;
            }
            else
            {
                string sEditStatus = this.Request.QueryString["EditStatus"].ToString().Trim();
                if (sEditStatus == "1")
                {
                    int iback = MyNBC.InsertNewsBigClassInfo(sBigClassName, sOrderby, sPic, sDemo, DAddtime);
                    if (iback > 0)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存成功!');window.opener.location.reload();window.close();</script>");
                        return;
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存失败!');</script>");
                        return;
                    }
                }
                else
                {
                    int iback = 0;
                    try
                    {
                        iback = MyNBC.UpdateNewsBigClassInfo(sBigClassName, sOrderby, sPic, sDemo, DAddtime, sid);
                    }
                    catch
                    {
                    }

                    if (iback > 0)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');window.opener.location.reload();window.close();</script>");
                        return;
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!');</script>");
                        return;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Message.AlertMsg(this, "保存失败");
        }
    }
    #endregion
}
